package com.ushine.web.template.test.utils;

import org.springframework.stereotype.Component;

/**
 * @Author: yls
 * @Date 2022/3/15 16:34
 * @Description: 数值生成工具类
 * @Version 1.0
 **/
@Component
public class NumberTestUtils {
    /**
     * 功能描述:
     * 〈 按照对应的类型生成对应的数值 〉
     *
     * @param clazz 字段类型
     * @param number 数值
     * @return : T
     * @author : yls
     * @date : 2022/3/15 16:42
     */
    public Number getNumberValue(Class<? extends Number> clazz, Integer number) {
        String value = number + "";
        if (clazz == Byte.class) {
            return Byte.valueOf(value);
        } else if (clazz == Short.class) {
            return Short.valueOf(value);
        } else if (clazz == Integer.class) {
            return Integer.valueOf(value);
        } else if (clazz == Long.class) {
            return Long.valueOf(value);
        } else if (clazz == Float.class) {
            return Float.valueOf(value);
        } else if (clazz == Double.class) {
            return Double.valueOf(value);
        }
        return null;
    }
}
